/*
 * BanBu_RecomViewController
 * @description 本文件提供附近vip用户推荐界面的ViewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供附近vip用户推荐界面的ViewController
 */

#import "BanBu_RecomViewController.h"
#import "BanBu_ListCell.h"
#import "AppCommunicationManager.h"
#import "AppDataManager.h"

@interface BanBu_RecomViewController ()

@end

@implementation BanBu_RecomViewController


- (void)dealloc {
    [_dataSource release],_dataSource = nil;
    
    [_tableV release];
    _tableV = nil;
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = NSLocalizedString(@"recomment", nil);
    _dataSource = [[NSMutableArray alloc] initWithCapacity:0];
    _tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, __MainScreen_Height - 44) style:UITableViewStylePlain];
    _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableV.delegate = self;
    _tableV.dataSource = self;
    [self.view addSubview:_tableV];
    [self loadData];
    // Do any additional setup after loading the view from its nib.
}

- (void)loadData
{
    NSDictionary *parDic = [NSDictionary dictionaryWithObjectsAndKeys:@"40",@"countof",nil];
    [AppComManager getBanBuData:Banbu_Get_Vipuser_Nearby par:parDic delegate:self];
    [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"loadingNotice", nil) activityAnimated:YES];

}

- (void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:NO afterShow:0];
    if(error)
    {
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"error", nil) activityAnimated:NO duration:0];
    }
    else if([AppComManager respondsDic:resDic isFunctionData:Banbu_Get_Vipuser_Nearby])
    {
        [self.dataSource addObjectsFromArray:[resDic valueForKey:@"list"]];
        [_tableV reloadData];
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 84;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ListCellIdentifier = @"ListCellIdentifierrrrrrr";
    BanBu_ListCell *cell = (BanBu_ListCell *)[tableView dequeueReusableCellWithIdentifier:ListCellIdentifier];
    if(cell == nil)
    {
        cell = [[[BanBu_ListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ListCellIdentifier] autorelease];
        //            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        //            UIView *bgColorView = [[UIView alloc] init];
        //
        //            bgColorView.backgroundColor = [UIColor colorWithRed:0.011 green:0.509 blue:0.901 alpha:1];
        //            bgColorView.layer.masksToBounds = Y
        
    }

    if(_dataSource.count)
    {
            NSDictionary *buddy = [_dataSource objectAtIndex:indexPath.row];
            if(!buddy.count)
            {
                return cell;
            }
            [cell setAvatar:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"uface"]];
            [cell setName:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"pname"] andUserid:[buddy valueForKey:@"userid"]];
            [cell setAge:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"oldyears"] sex:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"gender"]];
            [cell setDistance:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"dmeter"] timeAgo:[[buddy valueForKey:keyPersonalInfo]
                                                                                                   valueForKey:@"dtime"]];
        //签名+城市
        NSString * cityStr = [[buddy valueForKey:keyPersonalInfo] valueForKey:@"incityofname"];
        if (cityStr && cityStr.length)
        {
            [cell setSignature:[NSString stringWithFormat:@"[%@] %@",cityStr,[[buddy valueForKey:keyPersonalInfo] valueForKey:@"sayme"]]];
        }
        else
        {
            [cell setSignature:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"sayme"]];
        }

            [cell setLastInfo:[MyAppDataManager getTheLastOnlineTime:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"ltime"]]];
            [cell setGreenBallOnline:[MyAppDataManager getTheSecondLastOnlineTime:[[buddy valueForKey:keyPersonalInfo] valueForKey:@"ltime"]]];
            [cell setVerify:![[[buddy valueForKey:keyPersonalInfo] valueForKey:@"verify"] isEqual:@"y"]];
            
            [cell setVIPFlag:[[[buddy valueForKey:keyPersonalInfo]valueForKey:@"userlevel"] integerValue]>0];
//            [cell setIfHaveMoreFaces:[[[buddy valueForKey:keyPersonalInfo] valueForKey:@"facelist"] count]>1];
    }
    return cell;

}
#pragma mark UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    NSDictionary *buddy = [_dataSource objectAtIndex:indexPath.row];
    
    
    BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:[buddy valueForKey:keyPersonalInfo]];
    [self.navigationController pushViewController:peopleFfofile animated:YES];
    [peopleFfofile release];
}

@end
